<!Doctype html>
<html>

<head>
    <title>oixan的博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8">
    <link rel="stylesheet" type="text/css" href="../css/blog.css">
   
</head>

<body>
    <div class="head">
        <div class="headnav">
            <div class="naveframe">
                <ul class="navlist">
                    <li>
                        <a href="../index.html">
                            主页
                        </a>
                    </li>
                    <li>
                        <a href="../bloglist.html">
                            博客
                        </a>
                    </li>
                    <li>
                        <a href="../about.html">
                            关于
                        </a>
                    </li>
                </ul>
            </div>
        </div>

        <div class="headtext">
            <div class="headtext1">世界很简单，人类很复杂。</div>
            <div class="headtext2">浮生若梦，寻寻觅觅。</div>
        </div>
    </div>

    <div class="contents-all">
        <div class="contents">

            <div class="frame">
                <div class="title">
                    <h3>广东车牌城市与对应字母查询</h3>
                </div>
                <div class="dtime">时间：2019-05-18</div>
                <div class="detail">

                    <p style="margin-left: 1%">输入字母或者城市其中一个字都可以查</p>
                    <p></p>
                    <input id="city" style="margin-left: 1%" type="text" placeholder="输入关键字查询" title="输入关键字查询"></input>
                    <p></p>
                    <div id="sh" style="margin-left: 1%;line-height:1.2em;font-size: 1.5em"></div>
                    <p></p>

                    <script>
                        var myarr = [{ "广州": "粤A" }, { "深圳": "粤B" }, { "珠海": "粤C" }, { "汕头": "粤D" }, { "佛山": "粤E" }, { "韶关": "粤F" }, { "湛江": "粤G" }, { "肇庆": "粤H" }, { "江门": "粤J" }, { "茂名": "粤K" }, { "惠州": "粤L" }, { "梅州": "粤M" }, { "汕尾": "粤N" }, { "河源": "粤P" }, { "阳江": "粤Q" }, { "清远": "粤R" }, { "东莞": "粤S" }, { "中山": "粤T" }, { "潮州": "粤U" }, { "揭阳": "粤V" }, { "云浮": "粤W" }, { "佛山顺德": "粤X" }, { "佛山南海": "粤Y" }, { "港澳台进入内地车辆": "粤Z" }, { "官方专用车辆": "粤O" }];
                        var myinput = document.getElementById('city');
                        myinput.oninput = function () {//监听输入框
                            var cityval = document.getElementById('city').value;
                            var result = '';
                            if (!isval(cityval)) {//判断是否全空格和排除cityval空值str.indexOf(cityval)=0
                                cityval = Trim(cityval);//去前后空格
                                isen = checkEng(cityval);
                                if (isen) {
                                    cityval = cityval.toUpperCase();//判断是字母的话转大写
                                }

                                //查城市名字
                                for (i in myarr) {//历遍数组

                                    for (name in myarr[i]) {//取到前面城市名
                                        if (name.indexOf(cityval) != -1) {//输入的文字是否在城市字符串内,模糊查询
                                            result += name + ":" + myarr[i][name] + "；";
                                            break;
                                        }
                                    }
                                }

                                //查牌照字母
                                for (i in myarr) {
                                    for (name in myarr[i]) {
                                        if ((myarr[i][name]).indexOf(cityval) != -1) {
                                            result += name + ":" + myarr[i][name] + "；";
                                            break;
                                        }
                                    }
                                }
                            }
                            if (result) {
                                document.getElementById('sh').innerHTML = result;
                            } else {
                                document.getElementById('sh').innerHTML = "";
                            }
                        }

                        function checkEng(st) {//判断输入是否为字母
                            var reg = /^[A-Za-z]+$/;
                            return reg.test(st)
                        }

                        function Trim(str) {//去前后空格
                            return str.replace(/(^\s*)|(\s*$)/g, "");
                        }

                        function isval(a) {//判断是否为空
                            return a.match(/^[ ]*$/);
                        }

                    </script>


                </div>
                <a href="javascript:void(0)" onclick="showPg()">返回</a>
            </div>


        </div>
    </div>
    <div class="footer">
        <div class="footertext">©2018,oixan博客</div>
    </div>
    <span id="backtop" onclick="topFunction()">返回顶部</span>
</body>
<script src="../js/fanhuiye.js"></script>

</html>